<?php

/**
 *		//微薄系统用户设置控制页面//
 *		//这是一份试验品，由大街编写（zhongmingzi@gmail.com）
 *		//本程序默认环境：Zend Optimizer Yes / 3.3.3
 *		//		Apache/2.0.63 (Win32) PHP/5.2.12
 *		//		MySQL 支持 Yes / client lib version 5.0.89
 *		//		GD library Yes / bundled (2.0.34 compatible)
 *		//		eAccelerator/Memcache/xcache Yes
 *		//		cURL support enabled
 *		//时间：2011 03 25 02:56:20//
 */
 
 $action = getgpc('action');
 $do = getgpc('do');
 
 if($action == 'register') {
	if($_POST) {
		$uid = member::register($_G['gp_email'], $_G['gp_username'], $_G['gp_password'], $_G['gp_passwordsec']);
		if($uid > 0) dheader("location:".URL);
		else echo $uid;
	}
 } elseif($action == 'login') {
	if($_POST) {
		$uid = member::login($_G['gp_email'], $_G['gp_password']);
		if($uid > 0) dheader("location:".URL);
		else echo $uid;
	}
 } elseif($action == 'mail') {
	if($_G['uid'] == 0) dheader("location:".URL);
	if($do == 'private' || !$do) {
		$all = pmmodel::get_pm_list($_G['uid'], 'inbox', 'privatepm', $_G['page'], 5);
		$ls = $all['data'];
		$page = page($all['page']['ptotal'], $_G['page'], '&page=');
		//echo SECURL;
		//var_dump($all);
	} elseif($do == 'common') {
		
	} elseif($do == 'new') {
		if($_POST['msubmit']) {
			$msgfrom = array('uid' => $_G['uid'], 'username' => $_G['username']);
			//$msgfrom = array('uid' => 2, 'username' => 'test');
			if($id = pmmodel::sendpm($_G['gp_pmsubject'], $_G['gp_pmtext'], $msgfrom, 7) <= 0) echo $id;
		}
	} elseif($do == 'unread') {
		$all = pmmodel::get_pm_list($_G['uid'], 'inbox', 'newpm', $_G['page'], 5);
		$ls = $all['data'];
		$page = page($all['page']['ptotal'], $_G['page'], '&page=');
	} elseif($do == 'node') {
		if($_POST['rsubmit']) {
			$msgfrom = array('uid' => $_G['uid'], 'username' => $_G['username']);
			$touid = (int) $_G['gp_touid'];
			if($id = pmmodel::sendpm('', $_G['gp_replymail'], $msgfrom, $touid) <= 0) echo $id;
			//else 
		}
		$touid = (int) $_G['gp_touid'];
		$t = TIMESTAMP + 2;
		$ls = pmmodel::get_pm_by_touid($_G['uid'], $touid, 0, $t);
		//var_dump($all);
	}
	include_once template("common/mail");
	exit;
 } elseif($action == 'change') {
	if($_G['uid'] == 0) dheader("location:".URL);
	if(isset($_POST['msubmit'])) {
		if(member::chmember()) dheader("location:".$_SERVER['HTTP_REFERER']);
	} elseif(isset($_POST['asubmit'])) {
		$id = member::chavatar('mavatar');
		if($id > 0) dheader("location:".$_SERVER['HTTP_REFERER']);
		else echo $id;
	} elseif(isset($_POST['psubmit'])) {
		$id = member::chpw($_G['uid'], $_G['gp_rpassword'], $_G['gp_rrpassword'], $_G['gp_mpassword']);
		if($id > 0) dheader("location:".$_SERVER['HTTP_REFERER']);
		else echo $id;
	}
 } elseif($action == 'logout') {
	if(member::logout($_G['gp_formhash'])) dheader("location:".$_SERVER['HTTP_REFERER']);
 } elseif($action == 'friend') {
	include libfile('class/friend');
	$direction = $do == 'fans' ? 2 : ($do == 'follow' ? 1 : 3);
	$default = URL."/static/image/common/default.s.jpg";
	$all = friendmodel::get_list(1, $_G['page'], 84, $direction, 1);
	$ls = $all['data'];
	$page = page($all['page']['ptotal'], $_G['page'], '&page=');
 }

 include_once template("common/member");